﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
/// <summary>
/// Summary description for PhanHoiCtr
/// </summary>
public class PhanHoiCtr
{
	public PhanHoiCtr()
	{
	}
    public EPhanHoi LayPhanHoi(string MaPH)
    {

        try
        {
            DataTable tablePhanHoi = DataProvider.GetData("Select * from PhanHoi Where MaPH=@MaPH and TrangThai=1","@MaPH",MaPH);
            EPhanHoi PhanHoi = new EPhanHoi();
            PhanHoi.MaPH = Int32.Parse( tablePhanHoi.Rows[0]["MaPH"].ToString());
            PhanHoi.MaSP = Int32.Parse( tablePhanHoi.Rows[0]["MaSP"].ToString());
            PhanHoi.NoiDung = tablePhanHoi.Rows[0]["NoiDung"].ToString();
            PhanHoi.DaKiemTra = tablePhanHoi.Rows[0]["DaKiemTra"].ToString();
            PhanHoi.Email = tablePhanHoi.Rows[0]["Email"].ToString();
            return PhanHoi;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public  DataTable LayPhanHoi()
    {

        try
        {
            string sql = "select * from PhanHoi where TrangThai=1";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public DataTable LayPhanHoi1()
    {

        try
        {
            string sql = "select p.*,s.TenSP from PhanHoi p,SanPham s where p.TrangThai=1 and p.masp=s.masp";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool ThemPhanHoi(EPhanHoi PhanHoi)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO PhanHoi VAlUES(@MaPH,@MaSP,@NoiDung,@DaKiemTra,@Email,1)",
               "@MaPH", PhanHoi.MaPH, "@MaSP", PhanHoi.MaSP, "@NoiDung", PhanHoi.NoiDung, "@DaKiemTra", PhanHoi.DaKiemTra, "@Email", PhanHoi.Email);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public DataTable GetMaPhanHoi()
    {
        try
        {
            return DataProvider.GetData("Select MAx(MaPH) as MaPH from PhanHoi where Active=1");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void capNhatPhanHoiThanhdaXuLy(int maph)
    {
        string sql = "Update phanhoi set dakiemtra=@xuly where maph=@maph";
        DataProvider.ExecuteNonQuery(sql,"@xuly",true,"@maph",maph);
    }
    public bool xoaPhanHoi(int maph)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update  PhanHoi set trangThai=0 where maph=@maph","@MaPH",maph);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    
}